<script setup>
// import { getAdvert } from '@/api/my';

//响应式变量
const carouselList = ref([]);
const orderId = ref(0);
const check = ref(false);

// #ifdef MP-WEIXIN
// 在页面中定义插屏广告
let interstitialAd = null;

// 创建插屏广告实例
const successAdvertisement = () => {
  if (wx.createInterstitialAd) {
    interstitialAd = wx.createInterstitialAd({
      adUnitId: 'adunit-c6fdd0deae68ed9a'
    });
    interstitialAd.onLoad(() => {});
    interstitialAd.onError((err) => {
      console.error('插屏广告加载失败', err);
    });
    interstitialAd.onClose(() => {});
  }
  // 在适合的场景显示插屏广告
  if (interstitialAd) {
    interstitialAd.show().catch((err) => {
      console.error('插屏广告显示失败', err);
    });
  }
};
// #endif

//点击完成跳转订单详情
const comp = () => {
  uni.reLaunch({
    url: `/pages/orderdetails/orderdetails?id=${orderId.value}&check=${check.value}`
  });
};

//广告之间相互跳转url中间页
// const jump = (id, url) => {
//   if (!url || !id) {
//     return;
//   }
//   uni.navigateTo({
//     url: `/pages/url/url?url=${url}&id=${id}`
//   });
// };

// 获取广告
// const getAdvertData = async () => {
//   try {
//     const res = await getAdvert({ position: 'rentbox_popup' });
//     console.log('获取广告----->getAdvert', res);
//     carouselList.value = res.data;
//   } catch (error) {
//     console.error(error);
//   }
// };

/**
 * 生命周期函数--监听页面显示
 */
onShow(() => {
  // getAdvertData();
  // #ifdef MP-WEIXIN
  successAdvertisement();
  // #endif
});

/**
 * 生命周期函数--监听页面加载
 */
onLoad((options) => {
  if (!options.id) {
    uni.reLaunch({ url: '/pages/home/home' });
  } else {
    orderId.value = options.id;
    check.value = options.check;
  }
});
</script>

<template>
  <swiper class="carousel_swiper" indicator-color="#f4f4f4" indicator-active-color="#4eb8b8" autoplay interval="5000" circular>
    <swiper-item v-for="item in carouselList" :key="item.id" @click="jump(item.id, item.forward)" style="display: flex; justify-content: center; align-items: center">
      <image class="carouselImg" :src="item.url1" mode="aspectFill"></image>
    </swiper-item>
  </swiper>
  <view class="pay_success">
    <image class="success" src="@/static/images/icon_popup_success.png"></image>
  </view>
  <view class="pay_ok">租借成功</view>
  <view class="comp_My" @click="comp">
    <view class="text">完成</view>
  </view>

  <ad-custom unit-id="adunit-c6fdd0deae68ed9a" ad-intervals="30"></ad-custom>
</template>

<style lang="scss" scoped>
page {
  background: rgba(255, 255, 255, 1);
}
.carousel_swiper {
  display: flex;
  justify-content: center;
  margin-top: 20rpx;
  height: 144rpx;
  .carouselImg {
    height: 144rpx;
    width: 690rpx;
    border-radius: 12rpx;
  }
}
.pay_success {
  display: flex;
  justify-content: center;
  margin-top: 30rpx;
  width: 750rpx;
  height: 320rpx;
  .success {
    width: 340rpx;
    height: 320rpx;
  }
}

.pay_ok {
  margin-top: 21rpx;
  line-height: 40rpx;
  text-align: center;
  font-size: 28rpx;
  font-weight: bold;
  color: rgba(38, 38, 38, 1);
}
.comp_My {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 400rpx auto;
  width: 650rpx;
  height: 90rpx;
  border-radius: 50rpx;
  background-color: #2185f5;
  .text {
    font-size: 36rpx;
    font-weight: 400;
    color: rgba(255, 255, 255, 1);
  }
}
</style>
